﻿using System;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using WC.Common;
using WC.Model;
using WC.DBUtility;
using WC.IDAL;
using WC.Tool;

namespace WC.DAL
{
    public class AdminDAL : IAdmin
    {
        private EntityControl control;

        public AdminDAL()
        {
            control = EntityControl.CreateEntityControl("WC.Model");
        }

        #region NHibernate 方法
        public void Add(AdminInfo Admin_)
        {
            control.AddEntity(Admin_);
        }

        public void Update(AdminInfo Admin_)
        {
            control.UpdateEntity(Admin_, Admin_.id);
        }

        public void Delete(int id)
        {
            AdminInfo Admin_ = new AdminInfo();
            Admin_.id = id;
            control.DeleteEntity(Admin_);
        }

        public AdminInfo GetById(int id)
        {
            return (AdminInfo)control.GetEntity("WC.Model.AdminInfo", "id", id.ToString());
        }

        public IList GetAll(string where, string orderBy)
        {
            if (!Utils.CheckSql(where))
            {
                throw new Exception("sql注入非法字符串! -- " + where);
            }
            return control.GetEntities("WC.Model.AdminInfo", where, orderBy);
        }
        #endregion
    }
}
